<?php

function getSalt()
{
    return microtime(true) * 10000;
}

function jsonReturn($data)
{
    echo json_encode($data);
    exit;
}

function isBase64($string) {
    $decoded = base64_decode($string, true);
    return ($decoded !== false && json_last_error() == JSON_ERROR_NONE);
}

function rsaEncrypt($password)
{
    $pubKey = file_get_contents('public.pub');
    $encrypted = "";
    $result = openssl_public_encrypt($password, $encrypted, $pubKey);
    return $encrypted;
}

function rsaDecrypt($encrypted)
{
    $privKey = file_get_contents('private.pem');
    isBase64($encrypted) && $encrypted = base64_decode($encrypted);
    $result = openssl_private_decrypt($encrypted, $decrypted, $privKey);
    return $decrypted;
}